from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# 设置Edge浏览器的路径
edge_driver_path = 'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe'  # 修改为你的实际路径

# 初始化Edge浏览器
driver = webdriver.Edge(executable_path=edge_driver_path)

try:
    # 打开网易云课堂登录页面
    driver.get("https://study.163.com/member/login.htm")

    # 等待页面加载完成
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "email")))

    # 点击"邮箱登录"选项
    email_login_button = driver.find_element(By.ID, "emailLoginTab")
    email_login_button.click()

    # 输入邮箱账号
    email_input = driver.find_element(By.ID, "email")
    email_input.send_keys("test001@126.com")

    # 输入密码
    password_input = driver.find_element(By.NAME, "password")
    password_input.send_keys("test123456")

    # 取消勾选 "十天内免登录"
    remember_me_checkbox = driver.find_element(By.ID, "rememberMeCheckbox")
    if remember_me_checkbox.is_selected():
        remember_me_checkbox.click()

    # 点击登录按钮
    login_button = driver.find_element(By.ID, "dologin")
    login_button.click()

    # 等待登录结果
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "user-info")))

finally:
    # 关闭浏览器
    time.sleep(5)  # 等待5秒以观察结果
    driver.quit()
